package com.project.service.imp;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.imp.IUserDaoImp;
import com.project.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImp implements UserService {
    @Autowired
    private IUserDao dao;

    @Override
    public UserBean login(String userName, String passWord) {
        return dao.login(userName, passWord);
    }

    @Override
    public void updatePassWord(Integer id, String passWord) {
        dao.updatePassWord(id, passWord);
    }

    @Override
    public boolean addUser(UserBean userBean) {
        if (dao.checkName(userBean.getUserName())) {
            dao.addUser(userBean);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public boolean checkName(String userName) {
        return dao.checkName(userName);
    }

    @Override
    public List<UserBean> findAll() {
        return dao.findAll();
    }

    @Override
    public UserBean findById(Integer id) {
        return dao.findById(id);
    }

    @Override
    public boolean delUser(Integer id, UserBean loginUser) {
        if (id != loginUser.getId()) {
            dao.delUser(id);
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void updateUserGrade(Integer id, String grade) {
        dao.updateUserGrade(id, grade);
    }
}
